// 订单
const mongoose = require("mongoose");

module.exports = mongoose.model("orders", {
  useid: {
    type: String,
    required: true,
  },
  key: {
    //订单编号
    type: Number,
    required: true,
  },
  time: {
    //下单时间
    type: Number,
    required: true,
  },
  paymentMethod: {
    //支付方式
    type: String,
    required: true,
  },
  productAmount: {
    //商品总金额
    type: Number,
    required: true,
  },
  deliveryFee: {
    //配送费
    type: Number,
    required: true,
    default: 0,
  },
  payAmount: {
    //实付总金额
    type: Number,
    required: true,
  },
  productQuantity: {
    //商品总数量
    type: Number,
    required: true,
  },
  /* 
    
    { id: 1, text: "待支付" },
    { id: 2, text: "待配送" },
    { id: 3, text: "配送中" },
    { id: 4, text: "交易完成" },
    { id: 5, text: "交易关闭" },
      */
  state: {
    //状态
    type: Number,
    required: true,
  },

  AddressId: {
    //用户收货地址
    // type: mongoose.SchemaTypes.ObjectId,
    // ref: "address",
    type:Object,
    required: true,
  },
  appointmentTime: {
    //预约时间
    type: Number,
  },
  orderItem: {
    //订单商品列表
    type: Array,
    required: true,
    default: [
      {
        img: "https://cdn7.axureshop.com/demo/1970439/images/%E8%AE%A2%E5%8D%95%E8%AF%A6%E6%83%85_1/u4776.png",
        name: "白蘑菇230g/盒",
        unit_price: 4.29,
        unit: "盒",
        num: 1,
        total_price: 4.29,
      },
      {
        img: "https://cdn7.axureshop.com/demo/1970439/images/%E8%AE%A2%E5%8D%95%E8%AF%A6%E6%83%85_1/u4776.png",
        name: "白蘑菇300g/盒",
        unit_price: 5,
        unit: "盒",
        num: 2,
        total_price: 10,
      },
    ],
  },
});
